import { observable, action, computed, runInAction } from 'mobx';

class AppleBasket {
  // todo 列表
  @observable id = 1;
  @observable isPicking = false;
  @observable appleList = [];
  @action.bound toAddApple () {
    this.isPicking = true
    setTimeout(() => {
      runInAction(() => {
        this.appleList.push({
          id: this.id++,
          weight: Math.floor(200 + Math.random() * 50),
          hasEat: false
        })
        this.isPicking = false
      })
    }, 1000)
  }
  // 吃苹果
  @action.bound toEatApple (id) {
    const cur = this.appleList.find(item => item.id === id)
    cur.hasEat = true
  }
  //当前苹果数组
  @computed get hasAppleArr () {
    return this.appleList.filter(item => !item.hasEat)
  }
  //吃掉的苹果数组
  @computed get hasEatArr () {
    return this.appleList.filter(item => item.hasEat)
  }
}
const appleBasket = new AppleBasket();

export default appleBasket;